<template>
  <div
    class="wrap"
    style="height: 100vh; overflow-y: hidden; padding-bottom: 0.6rem"
  >
    <Navbar :appTitle="title" />
    <ContactPickers
      :visible="selectShow"
      ref="mychild"
      :max="1"
      @closePicker="selectShow = false"
      @confirm="
        (a, b) => {
          formData.inventoryUserId = a;
          formData.realname = b[0].realname;
          selectShow = false;
        }
      "
    />
    <div v-if="nobackfff" class="wrap">
      <!-- 头部表单开始 -->
      <div style="background: #fff; padding: 0.1rem; margin-top: 0.1rem">
        <div class="body">
          <div>
            <p class="titles"><span style="color: #f25643">*</span>盘点单号</p>
            <van-field
              v-model="formData.inventoryCode"
              placeholder="不输入则自动生成"
              :disabled="isEdit"
            >
              <template v-if="!isEdit" #button>
                <a @click="genEntityCode">自动生成</a>
              </template>
            </van-field>
            <div class="bottomLine"></div>
          </div>

          <div style="margin-top: 0.1rem">
            <p class="titles"><span style="color: #f25643">*</span>盘点人</p>
            <van-field
              :is-link="!formData.realname"
              :value="formData.realname"
              placeholder="请选择"
              @click="isEdit ? '' : (selectShow = true)"
              readonly
              :disabled="isEdit"
            >
              <div
                slot="right-icon"
                v-show="!!formData.realname && !queryId"
                @click.stop="confirmDdtjr"
              >
                <img
                  src="~@/assets/img/filedClear.png"
                  alt=""
                  style="width: 0.16rem"
                />
              </div>
            </van-field>

            <div class="bottomLine"></div>
          </div>
          <div style="margin-top: 0.1rem">
            <p class="titles"><span style="color: #f25643">*</span>盘点仓库</p>
            <van-field-select-picker
              :supportClear="queryId ? false : true"
              :disabled="isEdit"
              label=""
              placeholder="请选择"
              v-model="formData.warehouseId"
              :columns="columnsa"
              right-icon="arrow"
              :option="{ label: 'title', value: 'value' }"
              @confirm="selectWarehouse"
            />
            <div class="bottomLine"></div>
          </div>
          <div style="margin-top: 0.1rem">
            <p class="titles"><span style="color: #f25643">*</span>盘点类型</p>
            <van-field-select-picker
              :supportClear="queryId ? false : true"
              :disabled="isEdit"
              label=""
              placeholder="请选择"
              v-model="formData.inventoryType"
              :columns="columnsb"
              right-icon="arrow"
              :option="{ label: 'title', value: 'value' }"
            />
          </div>
        </div>
      </div>
      <!-- 盘点物品选择 -->
      <div class="goodsWrap">
        <div class="goodsList" v-if="formData.goodsList.length > 0">
          <p class="total">
            已盘点物品：<span style="color: #1890ff">{{
              formData.goodsList.length
            }}</span
            >；待盘点物品：<span style="color: #1890ff">{{
              unCompleteTotal
            }}</span>
          </p>
          <div
            class="goodsBox"
            v-for="(item, index) in formData.goodsList"
            :key="index"
          >
            <p class="title">盘点物品({{ index + 1 }})</p>
            <div class="content">
              <div class="left">
                <img :src="getimgUrl(item.goodsId)" alt="" />
              </div>
              <div class="right">
                <div class="top">
                  <p class="code">
                    {{ item.goodsCode || "--" }}｜{{
                      item.goodsName || "--"
                    }}｜{{ item.spec || "--" }}
                  </p>
                  <img
                    @click="toChangeNum(item)"
                    src="../../../assets/diandian.png"
                    alt=""
                  />
                </div>
                <div class="btn">
                  <div>
                    <p class="key">账面合格品</p>
                    <p class="val">
                      {{ item.goodsQualifiedNum }}{{ item.assistUnit }}
                    </p>
                  </div>
                  <div>
                    <p class="key">账面报废品</p>
                    <p class="val">
                      {{ item.goodsScrapNum }}{{ item.assistUnit }}
                    </p>
                  </div>
                  <div>
                    <p class="key">账面合格品(F)</p>
                    <p class="val">
                      {{ item.goodsQualifiedNumTextAssistUnit || "--" }}
                    </p>
                  </div>
                  <div>
                    <p class="key">账面报废品(F)</p>
                    <p class="val">
                      {{ item.goodsScrapNumTextAssistUnit || "--" }}
                    </p>
                  </div>
                  <div>
                    <p class="key">盘点合格品</p>
                    <p class="val" :style="{ color: setColor(item) }">
                      {{ item.inventoryGoodsQualifiedNum || 0
                      }}{{ item.assistUnit }}
                    </p>
                  </div>
                  <div>
                    <p class="key">盘点报废品</p>
                    <p class="val" :style="{ color: setColor2(item) }">
                      {{ item.inventoryGoodsScrapNum || 0
                      }}{{ item.assistUnit }}
                    </p>
                  </div>
                  <div>
                    <p class="key">盘点合格品(F)</p>
                    <p class="val" :style="{ color: setColor(item) }">
                      {{
                        item.inventoryGoodsQualifiedNumTextAssistUnit || "--"
                      }}
                    </p>
                  </div>
                  <div>
                    <p class="key">盘点报废品(F)</p>
                    <p class="val" :style="{ color: setColor2(item) }">
                      {{ item.inventoryGoodsScrapNumTextAssistUnit || "--" }}
                    </p>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="addgoods">
          <a @click="listShowit">添加盘点物品</a>
        </div>
        <div style="margin: 0.12rem 0" v-if="showExam">
          <Examine
            @submitProcess="submitProcess"
            @getUserState="getUserState"
            type="0"
            :key="examKey"
            id="WMS_WAREHOUSE_INVENTORY"
            ref="examine"
          />
          <div style="height: 0.26rem"></div>
        </div>
        <!-- <div style="height: 0.5rem"></div> -->
      </div>
    </div>
    <div v-else style="height:'100vh;background:#fff"></div>
    <!-- <div style="height: 1rem"></div> -->

    <!-- <div style="height: 0.5rem"></div> -->
    <div class="search-bottom" v-show="!this.columnsData.listShow">
      <van-button :loading="loading" class="btncancel" @click="sendData('all')"
        >盘点完毕</van-button
      >
      <van-button :loading="loading" class="btnconfirm" @click="subimtConfirm()"
        >暂存</van-button
      >
    </div>
    <!-- 物品选择弹窗 -->
    <selectList
      v-if="columnsData.listShow"
      :columnsData="columnsData"
      ref="selectList"
      @getCheckedValue="getCheckedValue"
      @handleList="handleList"
      @listData="listData"
    >
      <!-- 搜索插槽 -->
      <div slot="title">
        <!-- <van-search v-model="value" show-action placeholder="请输入搜索关键词">
          <template #action>
            <div @click="searchQuery">搜索</div>
          </template>
        </van-search> -->
        <div class="selectTotal">
          <p>
            1、<span>{{ checkWareName(formData.warehouseId) }}</span
            >待盘点物品<span>{{ unCompleteTotal }}</span
            >种，当前已盘点物品<span>{{ formData.goodsList.length }}</span
            >种；
          </p>
          <p style="margin-top: 0.05rem">2、本页面仅展示待盘点物品。</p>
        </div>
      </div>
      <!-- 列表插槽 -->
      <div slot="head" class="selectList" slot-scope="{ item, index }">
        <div class="content">
          <div class="left">
            <img :src="getimgUrl(item.goodsId)" alt="" />
          </div>
          <div class="right">
            <div class="top">
              <p class="code">
                {{ item.goodsCode || "--" }}｜{{ item.goodsName || "--" }}｜{{
                  item.spec || "--"
                }}
              </p>
            </div>
            <div class="btn">
              <div>
                <p class="key">账面合格品</p>
                <p class="val">
                  {{ item.goodsQualifiedNum }}{{ item.assistUnit }}
                </p>
              </div>
              <div>
                <p class="key">账面报废品</p>
                <p class="val">{{ item.goodsScrapNum }}{{ item.assistUnit }}</p>
              </div>
            </div>
            <div class="btn">
              <div>
                <p class="key">账面合格品(F)</p>
                <p class="val">
                  {{ item.goodsQualifiedNumTextAssistUnit || "--" }}
                </p>
              </div>
              <div>
                <p class="key">账面报废品(F)</p>
                <p class="val">
                  {{ item.goodsScrapNumTextAssistUnit || "--" }}
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </selectList>
    <changeNum
      :changeNumData="changeNumData"
      v-if="changeNumData.show"
      @goBack="goBack"
    >
    </changeNum>
    <van-dialog
      v-model="showDialog"
      show-cancel-button
      confirm-button-color="#1890FF"
      @confirm="submitTo"
    >
      <div
        slot="title"
        style="
          text-align: left;
          margin: 0.1rem 0.19rem;
          color: #191f25;
          font-size: 0.16rem;
        "
      >
        <van-icon name="question-o" size="0.20rem" color="#FF943E" /><span
          style="margin-left: 0.07rem"
          >确定盘点完毕吗？</span
        >
      </div>
      <div style="margin: 0.1rem 0.46rem 0.3rem 0.46rem; color: #888888">
        盘点完毕后，无法更改盘点数据
      </div>
      <div style="background: #f0f0f0; width: 100%; height: 0.01rem"></div>
    </van-dialog>
  </div>
</template>

<script>
import Examine from "@/components/examine";
import Navbar from "@/components/navBar/navBar_right";
import { getAction, postAction } from "@/api/manage";
import VanFieldSelectPicker from "@/components/ActionSheet/VanFieldSelectPicker";
import { apiBaseUrlDownload } from "@/utils/request";
import ContactPickers from "@/components/choiceuse/ContactPickers";
import selectList from "@/components/pageList/selectList";
import { APILX } from "@/api/requestLx";
import { Dialog } from "vant";
import changeNum from "@/components/pageList/changeNum";
import { accDiv, accDivMin } from "@/utils/util";
import { findUnitListByGoodsIdSync } from "@/api/mobile";
const getFileListByIds = (params) =>
  getAction("/sys/common/getFileListByIds", params);
export default {
  name: "stockCheckForm", //盘点单
  components: {
    Navbar,
    VanFieldSelectPicker,
    ContactPickers,
    selectList,
    changeNum,
    Examine,
  },
  data() {
    return {
      showExam: true,
      processDataVo: {},
      sendType: "",
      showPeopleSlect: false,
      examKey: 1,
      nobackfff: true,
      isEdit: false,
      queryId: "", //继续盘点ID
      showDialog: false,
      unCompleteTotal: 0,
      goodsIds: "", //已选择的盘点数据goodsId
      title: this.$route.meta.title,
      detailData: {},
      type: this.$route.query.type,
      formData: {
        inventoryUserId: "", //盘点人id
        inventoryCode: "",
        goodsList: [],
        realname: "",
      },
      selectShow: false,
      columnsa: [], //仓库
      columnsb: [], //类型
      loading: false,
      //物品选择弹窗
      ids: "",
      changeNumData: {
        show: false,
      },
      columnsData: {
        listShow: false, //控制列表选择显示
        title: "添加盘点物品", //列表名称
        checkedShow: true, //列表是否支持多选
        operationTxt: "确定", //选择按钮名称
        listUrl: "wms/wmsWarehouseInventory/unCompleteList", //列表接口
        columns: {
          //列表是否使用插槽
          headSlot: true, //头部插槽
          bodySlot: true, //中间内容插槽
          labelSlot: true, //标签插槽
          footSlot: true, //底部插槽
        },
      },
      imgUrlList: [],
      oldItem: {},
    };
  },
  // 路由返回时先判断当前页是否存在弹窗，有就先关闭弹窗不返回，直到所有弹窗关闭再返回
  beforeRouteLeave(to, from, next) {
    let that = this;
    switch (true) {
      case that.showPeopleSlect:
        that.$refs.examine.closePicker();
        next(false);
        break;
      // that.showSearchTag是当前页的筛选弹窗，that.$refs.SearchTag.ddthrVisible是子组件筛选弹窗内的其他弹窗例如人员选择
      case that.changeNumData.show:
        that.oldItem.inventoryGoodsQualifiedNum =
          that.oldItem.sonGoodsQualifiedNum;
        that.oldItem.inventoryGoodsScrapNum = that.oldItem.sonGoodsScrapNum;
        that.goBack(that.oldItem);
        if (this.queryId) {
          this.title = "继续盘点";
        } else {
          this.title = "新建盘点单";
        }
        next(false);
        break;
      case that.columnsData.listShow:
        that.columnsData.listShow = false;
        if (this.queryId) {
          this.title = "继续盘点";
        } else {
          this.title = "新建盘点单";
        }
        next(false);
        break;
      case that.ddthrVisible:
        that.ddthrVisible = false;
        next(false);
        break;
      case !that.changeNumData.show &&
        !that.columnsData.listShow &&
        !that.ddthrVisible:
        next();
        break;
    }
  },
  computed: {},
  mounted() {},
  created() {
    this.getdata();
    this.queryId = this.$route.query.id;
    this.getDetail();
  },
  methods: {
    sendData(type) {
      this.sendType = type;
      this.submitProcess();
    },
    submitProcess(e) {
      if (e && e.nodeDtos) {
        this.processDataVo = e;
        this.subimtConfirm(this.sendType);
      } else {
        // 调用子组件的方法获取数据
        this.$refs.examine.confirm();
      }
    },
    getUserState(v) {
      this.showPeopleSlect = v;
    },
    confirmDdtjr() {
      this.formData.inventoryUserId = "";
      this.formData.realname = "";
      console.log(this.formData, "formData");
    },
    getDetail() {
      if (this.queryId) {
        this.title = "继续盘点";
        this.isEdit = true;
        APILX.warehouseInventoryGetContinueInventoryInfo(this.queryId).then(
          (res) => {
            if (res.code == 200) {
              console.log(res, "resresresres");
              this.formData.inventoryUserId = res.result.inventoryUserId;
              this.formData.inventoryCode = res.result.inventoryCode;
              this.formData.inventoryType = res.result.inventoryType;
              this.formData.realname = res.result.inventoryUser;
              this.formData.warehouseId = res.result.warehouseId;
            } else {
              this.$antdMessage.error(res.message);
            }
          }
        );
        this.getAbleTableList();
        setTimeout(() => {
          this.getUnCompleteTotal();
        }, 500);
      } else {
        this.title = "新建盘点单";
      }
    },
    // 已盘点 编辑
    getAbleTableList() {
      // debugger
      let param = {
        id: this.queryId,
        pageNo: "1",
        pageSize: "999",
      };
      APILX.wmsWarehouseInventoryCompleteList(param).then((res) => {
        if (res.code == 200) {
          this.$nextTick(() => {
            this.formData.goodsList = res.result.records;
            this.resetTable();
            this.listData(res.result.records);
          });
          console.log(this.formData, "res继续盘点已盘点物料数据");
        } else {
          this.$toast(res.message);
        }
      });
    },
    async resetTable() {
      for (let i = 0; i < this.formData.goodsList.length; i++) {
        const item = this.formData.goodsList[i];
        const unitRes = await findUnitListByGoodsIdSync({
          goodsId: item.goodsId,
        });
        if (item.goodsQualifiedUnitId) {
          let unitQ = unitRes.result.find(
            (u) => u.id == item.goodsQualifiedUnitId
          );
          let unitS = unitRes.result.find((u) => u.id == item.goodsScrapUnitId);
          item.selectUnitQ = unitQ
            ? unitQ.id
            : unitRes.result[unitRes.result.length - 1].id;
          item.selectUnitS = unitS
            ? unitS.id
            : unitRes.result[unitRes.result.length - 1].id;

          item.rateQ = unitQ ? unitQ.conversionRate : 1;
          item.rateQOld = unitQ ? unitQ.conversionRate : 1;

          item.rateS = unitS ? unitS.conversionRate : 1;
          item.rateSOld = unitS ? unitS.conversionRate : 1;

          // item.inventoryGoodsQualifiedNum = accDivMin(item.inventoryGoodsQualifiedNum, item.rateQ)
          // item.inventoryGoodsScrapNum = accDivMin(item.inventoryGoodsScrapNum, item.rateS)
        }
      }
    },
    subimtConfirm(all) {
      if (!this.formData.inventoryCode) {
        this.$toast("请输入盘点单号");
        return;
      }
      if (!this.formData.inventoryUserId) {
        this.$toast("请选择盘点人");
        return;
      }
      if (!this.formData.warehouseId) {
        this.$toast("请选择仓库");
        return;
      }
      if (!this.formData.inventoryType) {
        this.$toast("请选择盘点类型");
        return;
      }
      if (!this.formData.goodsList.length) {
        this.$toast("请选择物品");
        return;
      }
      this.saveForm(all);
    },
    saveForm(all) {
      if (all) {
        if (this.unCompleteTotal > 0) {
          this.$toast("监测到还有待盘点物品，无法盘点完毕");
        } else {
          this.submitApi = APILX.wmsWarehouseInventoryUpdateStatus;
          this.formData.complete = true;
          this.formData.id = this.queryId;
          // this.submitAll();
          this.showDialog = true;
        }
      } else if (this.queryId) {
        this.submitApi = APILX.wmsWarehouseInventoryEdit;
        this.formData.id = this.queryId;
        this.submitTo();
      } else {
        this.submitApi = APILX.wmsWarehouseInventoryAdd;
        this.submitTo();
      }
    },
    submitTo() {
      this.loading = true;
      this.formData.goodsList.forEach((item) => {
        if (item.inventoryGoodsQualifiedNum == "") {
          item.inventoryGoodsQualifiedNum = 0;
        }
        if (item.inventoryGoodsScrapNum == "") {
          item.inventoryGoodsScrapNum = 0;
        }
        item.goodsQualifiedUnitId = item.selectUnitQ; // 保存提交时的合格数单位
        item.goodsScrapUnitId = item.selectUnitS; // 保存提交时的报废数单位
      });
      let parameters = {
        ...this.formData,
      };
      if (this.sendType == "all") {
        parameters.processDataVo = this.processDataVo;
      }
      this.submitApi(parameters).then((res) => {
        if (res.code == 200) {
          this.loading = false;
          let subMsg =
            this.submitApi == APILX.wmsWarehouseInventoryUpdateStatus
              ? "盘点完毕！"
              : "盘点成功！";
          this.$toast(subMsg);
          // this.goBack();
          this.$router.go(-1);
        } else {
          this.loading = false;
          this.$toast(res.message);
        }
      });
    },

    setColor(item) {
      if (
        Number(item.inventoryGoodsQualifiedNum) > Number(item.goodsQualifiedNum)
      ) {
        return "#ff4d4f";
      } else {
        return "#00b042";
      }
    },
    setColor2(item) {
      if (Number(item.inventoryGoodsScrapNum) > Number(item.goodsScrapNum)) {
        return "#ff4d4f";
      } else {
        return "#00b042";
      }
    },
    // toChangeNum(item) {
    //   console.log(item, "item0.0.0.0.00");
    //   this.changeNumData.item = item;
    //   this.nobackfff = false;
    //   this.title = "添加盘点异常数据";
    //   this.changeNumData.show = true;
    // },
    async toChangeNum(item) {
      const unitRes = await findUnitListByGoodsIdSync({
        goodsId: item.goodsId,
      });
      item.unitList = unitRes.result;
      item.sonGoodsQualifiedNum = item.inventoryGoodsQualifiedNum;
      item.sonGoodsScrapNum = item.inventoryGoodsScrapNum;
      if (!item.selectUnitQ) {
        item.rateQ = 1;
        item.rateS = 1;
        item.rateQOld = 1;
        item.rateSOld = 1;
        item.selectUnitQ = unitRes.result[unitRes.result.length - 1].id;
        item.selectUnitS = unitRes.result[unitRes.result.length - 1].id;
      } else {
        let selectUnitQVal = unitRes.result.find(
          (u) => u.id == item.selectUnitQ
        );
        let selectUnitSVal = unitRes.result.find(
          (u) => u.id == item.selectUnitS
        );
        if (!selectUnitQVal) {
          item.selectUnitQ = unitRes.result[unitRes.result.length - 1].id;
          item.rateQ = 1;
          item.rateQOld = 1;
        } else {
          item.rateQ = selectUnitQVal.conversionRate;
          item.rateQOld = selectUnitQVal.conversionRate;
          console.log(
            "有选择的单位：",
            item.inventoryGoodsQualifiedNum,
            item.rateQ
          );
          item.inventoryGoodsQualifiedNum = accDiv(
            item.inventoryGoodsQualifiedNum,
            item.rateQ
          );
        }
        if (!selectUnitSVal) {
          item.selectUnitS = unitRes.result[unitRes.result.length - 1].id;
          item.rateS = 1;
          item.rateSOld = 1;
        } else {
          item.rateS = selectUnitSVal.conversionRate;
          item.rateSOld = selectUnitSVal.conversionRate;
          item.inventoryGoodsScrapNum = accDiv(
            item.inventoryGoodsScrapNum,
            item.rateS
          );
        }
      }
      item.inventoryGoodsQualifiedNumTextAssistUnit =
        item.inventoryGoodsQualifiedNumTextAssistUnit || "";
      item.inventoryGoodsScrapNumTextAssistUnit =
        item.inventoryGoodsScrapNumTextAssistUnit || "";
      console.log(item, "item0.0.0.0.00");
      this.oldItem = item;
      this.changeNumData.item = item;
      this.nobackfff = false;
      this.title = "添加盘点异常数据";
      this.changeNumData.show = true;
    },
    goBack(newItem) {
      if (this.queryId) {
        this.title = "继续盘点";
      } else {
        this.title = "新建盘点单";
      }
      this.nobackfff = true;
      this.changeNumData.show = false;
      this.changeNumData.item = newItem;
      console.log(this.changeNumData, "changeNumData back");
      console.log(this.formData.goodsList, "this.formData.goodsList back");
      this.formData.goodsList.forEach((item, index) => {
        if (item.goodsId == this.changeNumData.item.goodsId) {
          this.formData.goodsList[
            index
          ].inventoryGoodsQualifiedNum = this.changeNumData.item.inventoryGoodsQualifiedNum;
          this.formData.goodsList[
            index
          ].inventoryGoodsScrapNum = this.changeNumData.item.inventoryGoodsScrapNum;
        }
      });
    },
    selectWarehouse(val, index, resultValue) {
      this.formData.goodsList = [];
    },
    checkWareName(i) {
      let name = "";
      this.columnsa.forEach((item) => {
        if (item.value == i) {
          name = item.title;
        }
      });
      return name;
    },
    getimgUrl(v) {
      console.log(this.imgUrlList, "this.imgUrlList");
      console.log(v, "this.imgUrlList vvvvvv");
      return this.imgUrlList.find((e) => {
        return e.id === v;
      }).url;
    },
    //获取图片地址
    async listData(v) {
      console.log(v, "列表所有数据2");
      for (let i = 0; i < v.length; i++) {
        if (v[i].attachment) {
          await getFileListByIds({ ids: v[i].attachment }).then((res) => {
            if (res.code == 200) {
              if (res.result.length > 0) {
                this.imgUrlList.push({
                  url: `${apiBaseUrlDownload}jksaas-mgt/mgt/${res.result[0].uri}`,
                  id: v[i].goodsId,
                });
              } else {
                this.imgUrlList.push({
                  url: require("../../../assets/img/noPicture.jpg"),
                  id: v[i].goodsId,
                });
              }
            } else {
              this.imgUrlList.push({
                url: require("../../../assets/img/noPicture.jpg"),
                id: v[i].goodsId,
              });
            }
          });
        } else {
          this.imgUrlList.push({
            url: require("../../../assets/img/noPicture.jpg"),
            id: v[i].goodsId,
          });
        }
      }
    },
    //添加物品
    listShowit() {
      this.getGoodsIds();
      if (!this.formData.warehouseId) {
        return this.$toast("请先选择盘点仓库！");
      }
      this.columnsData.listUrl = `wms/wmsWarehouseInventory/unCompleteList?id=${
        this.$route.query.type === 1 ? this.$route.query.item.id : ""
      }&warehouseId=${this.formData.warehouseId}&goodsId=${this.goodsIds}`;
      this.getUnCompleteTotal();
      this.columnsData.listShow = true;
      this.title = "添加盘点物品";
    },
    // 获取当前goodsIds 逗号拼接
    getGoodsIds() {
      // 取this.formData.goodsList的goodsId逗号拼接
      let goodsIds = "";
      this.formData.goodsList.forEach((item) => {
        goodsIds += item.goodsId + ",";
      });
      goodsIds = goodsIds.slice(0, goodsIds.length - 1);
      this.goodsIds = goodsIds;
    },
    //下拉选择数据接口
    getdata() {
      // 仓库
      getAction("/wms/wmsWarehouse/queryList", {}).then((res) => {
        if (res.code == 200) {
          this.columnsa = res.result;
        } else {
          this.$toast(res.message);
        }
      });
      //   类型
      getAction("/sys/dict/getDictModel", {
        dictCode: "inventory_type",
      }).then((res) => {
        if (res.code == 200) {
          this.columnsb = res.result;
        } else {
          this.$toast(res.message);
        }
      });
    },
    /* 自动生成 */
    genEntityCode() {
      getAction("/sys/common/genEntityCode", {
        entityCode: "WMS_WAREHOUSE_INVENTORY",
      }).then((res) => {
        if (res.code == 200) {
          this.formData.inventoryCode = res.result;
        } else {
          this.$toast(res.message);
        }
      });
    },

    // 列表弹窗
    // 重置
    searchReset() {
      this.$refs.selectList.searchReset();
    },
    //列表点击事件
    handleList(id, item, type) {
      console.log(id, item, type, "点击列表");
    },
    // 获取选择的列表数据
    getCheckedValue(ids, item) {
      console.log(ids, item, "确定");
      console.log(ids, "确定 ids");
      item.forEach((e) => {
        if (!e.inventoryGoodsScrapNum) {
          e.inventoryGoodsScrapNum = e.goodsScrapNum;
          e.inventoryGoodsScrapNumTextAssistUnit =
            e.goodsScrapNumTextAssistUnit;
        }
        if (!e.inventoryGoodsQualifiedNum) {
          e.inventoryGoodsQualifiedNum = e.goodsQualifiedNum;
          e.inventoryGoodsQualifiedNumTextAssistUnit =
            e.goodsQualifiedNumTextAssistUnit;
        }
      });

      this.formData.goodsList = [...this.formData.goodsList, ...item];
      this.getUnCompleteTotal();
      this.title = "新建盘点单";
    },
    getUnCompleteTotal() {
      // 取待盘点数量
      this.getGoodsIds();
      getAction(
        `wms/wmsWarehouseInventory/unCompleteList?id=${
          this.$route.query.type === 1 ? this.$route.query.item.id : ""
        }&warehouseId=${this.formData.warehouseId}&goodsId=${this.goodsIds}`,
        {}
      ).then((res) => {
        if (res.code == 200) {
          this.unCompleteTotal = res.result.total;
        } else {
          this.$toast(res.message);
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/detail.scss";
.subimtForm {
  height: 0.6rem;
  line-height: 0.5rem;
  width: 100%;
  background: #fff;
  position: fixed;
  bottom: 0px;
  .button {
    width: 94vw;
    height: 0.39rem;
    text-align: center;
    margin-left: 3vw;
  }
}
.bottomLine {
  height: 0.01rem;
  background-color: #f0f0f0;
}
.titles {
  margin: 0;
  color: #191f25;
  font-size: 0.16rem;
}
// 盘点物品样式
.goodsWrap {
  margin-top: 0.15rem;
  .goodsList {
    .total {
      background: #f5f8ff;
      padding: 0.15rem;
      color: #888888;
      font-size: 0.14rem;
      margin-bottom: -0.1rem;
    }
    .goodsBox {
      background: #fff;
      margin-top: 0.1rem;
      .title {
        color: #191f25;
        font-weight: bold;
        font-size: 0.16rem;
        border-bottom: 1px solid #f5f5f5;
        padding: 0.15rem;
        margin: 0;
      }
      .content {
        display: flex;
        padding: 0.15rem;
        .left {
          img {
            width: 0.55rem;
            height: 0.55rem;
            border-radius: 0.05rem;
          }
        }
        .right {
          width: 2.8rem;
          margin-left: 0.15rem;
          .top {
            display: flex;
            font-size: 0.16rem;
            font-family: PingFang SC;
            font-weight: 500;
            color: #191f25;
            .code {
              width: 2.8rem;
              margin-bottom: 0.08rem;
              //   overflow: hidden;
              //   text-overflow: ellipsis;
              //   white-space: nowrap;
            }
            img {
              height: 0.18rem;
              margin-top: 0.03rem;
              //   float: right;
            }
          }
          .btn {
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            div {
              width: 50%;
              .key {
                font-size: 0.14rem;
                color: #8888;
                margin-bottom: 0.05rem;
              }
              .val {
                color: #191f25;
                font-size: 0.16rem;
                margin-bottom: 0.05rem;
                // overflow: hidden;
                // text-overflow: ellipsis;
                // white-space: nowrap;
              }
            }
          }
        }
      }
    }
  }
  .addgoods {
    background: #fff;
    font-size: 0.16rem;
    text-align: center;
    height: 0.5rem;
    line-height: 0.5rem;
  }
}
.selectList {
  .content {
    display: flex;
    padding: 0.15rem;
    .left {
      img {
        width: 0.55rem;
        height: 0.55rem;
        border-radius: 0.05rem;
      }
    }
    .right {
      width: 2.3rem;
      margin-left: 0.15rem;
      .top {
        display: flex;
        font-size: 0.16rem;
        font-family: PingFang SC;
        font-weight: 500;
        color: #191f25;
        .code {
          width: 2.5rem;
          margin-bottom: 0.08rem;
          //   overflow: hidden;
          //   text-overflow: ellipsis;
          //   white-space: nowrap;
        }
        img {
          height: 0.18rem;
          margin-top: 0.03rem;
          //   float: right;
        }
      }
      .btn {
        display: flex;
        justify-content: flex-start;
        flex-wrap: wrap;
        div {
          width: 50%;
          .key {
            font-size: 0.14rem;
            color: #8888;
            margin-bottom: 0.05rem;
          }
          .val {
            color: #191f25;
            font-size: 0.16rem;
            margin-bottom: 0.05rem;
          }
        }
      }
    }
  }
}
.selectTotal {
  background: #ffefe3;
  color: #ff943e;
  font-size: 0.11rem;
  padding: 0.15rem;
  p {
    margin: 0;
  }
}
.search-bottom {
  height: 0.5rem;
  width: 100%;
  background: #ffffff;
  // background: red;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  bottom: 0px;
  padding: 0.11rem;
  .btnconfirm {
    width: 1.72rem;
    height: 0.39rem;
    background: #1890ff;
    border-radius: 0rem;
    text-align: center;
    line-height: 0.39rem;
    color: #fff;
  }
  .btncancel {
    width: 1.72rem;
    height: 0.39rem;
    background: #f6f6f6;
    // border: 0.01px solid rgba(25, 31, 37, 0.12);
    border-radius: 0rem;
    text-align: center;
    line-height: 0.39rem;
  }
}
/deep/ .van-cell {
  padding: 0.14rem 0.08rem !important;
}
/deep/.van-button--default {
  border: none;
}
</style>
